package com.sale.system.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sale.common.core.message.RocketMqUtils;
import com.sale.system.domain.vo.MaterialMqMessageVo;
import com.sale.system.domain.vo.SysMaterialCodingMqVo;
import org.springframework.beans.factory.annotation.Value;

/**
 * @Description 物料发送管理类
 * @Param MaterialMq
 * @Date 23-02-20
 * @Author hl
 **/
public class MaterialMqUtil {

    @Value("${rocketmq.name-server}")
    private static String mqServer;

    @Value("${producer.group}")
    private static String mqGroup;

    @Value("${producer.send-message-timeout}")
    private static int mqTimeOut;

    /**
     * 物料新增/修改消息发送(mq)
     */
    public static void materialMqSend(MaterialMqMessageVo mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "material",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

    /**
     * 物料消息发送(mq)删除数据
     */
    public static void materialMqSendDelete(MaterialMqMessageVo mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "materialDelete",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }


    /**
     * 物料类别发送(mq)
     */
    public static void materialCodingMqSend(SysMaterialCodingMqVo mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "material_coding",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

    /**
     * 删除物料类别发送(mq)
     */
    public static void materialCodingMqSendDelete(SysMaterialCodingMqVo mq) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(mq);
        RocketMqUtils rocketMqUtils = new RocketMqUtils("192.168.0.10:9876", "producer-system-group", "material_coding_delete",3000);
        rocketMqUtils.sendMq("producer-system-group",json);
    }

}
